package cn.com.twoke.application.game.mario.game.util;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;

public class ShapeUtils {
    // 创建常见游戏形状
    public static Shape createRectangle(float width, float height) {
        return new Rectangle2D.Float(0, 0, width, height);
    }
    
    public static Shape createCircle(float radius) {
        return new Ellipse2D.Float(0, 0, radius*2, radius*2);
    }
    
    public static Shape createPolygon(float[] points) {
        Path2D path = new Path2D.Float();
        path.moveTo(points[0], points[1]);
        for (int i = 2; i < points.length; i += 2) {
            path.lineTo(points[i], points[i+1]);
        }
        path.closePath();
        return path;
    }
    
    // 形状变换辅助方法
    public static Shape transformShape(Shape shape, float x, float y, float rotation) {
        AffineTransform transform = new AffineTransform();
        transform.translate(x, y);
        transform.rotate(rotation);
        return transform.createTransformedShape(shape);
    }

    public static Shape transform(Shape shape, float x, float y) {
        AffineTransform transform = new AffineTransform();
        transform.translate(x, y);
        return transform.createTransformedShape(shape);
    }
}